//<SCRIPT LANGUAGE=javascript>
function _attachEvent(eventName,eventHandler,applID){
	var oEvents = _eventsObject();
	if( !oEvents )try{oEvents = _eventsObject(true);}catch(e){}
	if( !oEvents )return;
	if( typeof(applID) != 'object' )applID = {applID:applID};
	var eo = {name:eventName,callBack:eventHandler,eventObject:applID,self:self}
	_pushEvent(oEvents,eo);
	///Loacls
	function _pushEvent(oe,eo){
		var name,n;
		for( name in oe )
			n = parseInt(name.substr(1));
		try{oe["_"+((n||0)+1)] = eo;
		}catch(e){status=getFuncName()+":"+e.description}
	}
	function _clean(ae){		try{			for( var i=0; i < ae.length; i++ )				if( typeof(ae+'') == 'object' ){					ae.splice(i,1);					return _clean(ae);				}		}catch(e){ae = new Array();		}finally{return ae;}	}
}
function fireEvent(eventName,applID){
	var oEvents = _eventsObject();
	if( !oEvents )return;
	if( typeof(applID) != 'object' )applID = {applID:applID};
	var name;
	try{
		for( name in oEvents )
			try{
				if( oEvents[name].name == eventName && oEvents[name].self != self ){
					if( oEvents[name].eventObject.applID === undefined || applID.applID == oEvents[name].eventObject.applID )
						oEvents[name].callBack(mergeObjects(applID,oEvents[name].eventObject));
				}
			}catch(e){///alert("Event:"+eventName+"\n\n"+(e.description||"Unknown Error."))
				delete oEvents[name];
			}
	}catch(e){///alert("Event Manager:\n\n"+e.description)
		oEvents = {};
	}
}
function mergeObjects(objTo,objFrom){
	for( var n in objFrom )
		if( objTo[n] === undefined )
			objTo[n] = objFrom[n];
	return objTo;
}
function getFuncName(func){
var a = arguments.length? func : getFuncName.caller;
	if( !a )return "";
	a = a.toString().match(/function ([^\(\s]+)/)
	if( a && a[1] )return a[1];
	return "";
}
//function Opener(w){ return (dialogArguments||{}).opener || top.opener; }
//****** Fires ******
var SEND_TO_MENU = "sendToMenu";
var APPL_INFO_CHANGED = "applInfoChanged";
var RELOAD_VER_TREE = "ReloadVerTree";
var VER_TREE_CHANGED = "VER_TREE_CHANGED";
var DECISION_INFO_CHANGED = "DECISION_INFO_CHANGED";
var LIST_LOAD_NEXT = "LIST_LOAD_NEXT";
var LIST_REFRESH = "LIST_REFRESH"
var CREDIT_RE_PULLED = "CREDIT_RE_PULLED";
var SMART_FORM_CHANGED = "SMART_FORM_CHANGED";
var APPLICANT_SELECTED = "APPLICANT_SELECTED";
var FILTER_CHANGE = "FILTER_CHANGE";

var APPLICANT_SELECTED = "APPLICANT_SELECTED";
function     fireApplicantSelected(applID){     return fireEvent(APPLICANT_SELECTED,applID)};
function attachToApplicantSelected(func,applID){_attachEvent(APPLICANT_SELECTED,func,applID);}

function     fireCreditRepulled(applID){       fireEvent(CREDIT_RE_PULLED,applID)};
function attachToCreditRepulled(func,applID){_attachEvent(CREDIT_RE_PULLED,func,applID);}

function     fireListLoadNext(applID){       fireEvent(LIST_LOAD_NEXT,applID)};
function attachToListLoadNext(func,applID){_attachEvent(LIST_LOAD_NEXT,func,applID);}

function     fireListRefresh(applID){       fireEvent(LIST_REFRESH,applID)};
function attachToListRefresh(func,applID){_attachEvent(LIST_REFRESH,func,applID);}

function     fireDecisionInfoChanged(applID){       fireEvent(DECISION_INFO_CHANGED,applID)};
function attachToDecisionInfoChanged(func,applID){_attachEvent(DECISION_INFO_CHANGED,func,applID);}

function     fireSendToMenu(applID){       fireEvent(SEND_TO_MENU,applID)};
function attachToSendToMenu(func,applID){_attachEvent(SEND_TO_MENU,func,applID);}

function     fireApplInfoChanged(applID){       fireEvent(APPL_INFO_CHANGED,applID)};
function attachToApplInfoChanged(func,applID){_attachEvent(APPL_INFO_CHANGED,func,applID);}

function   fireOnReloadVerTree(applID){     fireEvent  (RELOAD_VER_TREE,applID)};
function attachToReloadVerTree(func,applID){_attachEvent(RELOAD_VER_TREE,func,applID);}

function     fireVerTreeChanged(applID){    fireEvent   (VER_TREE_CHANGED,applID)};
function attachToVerTreeChanged(func,applID){_attachEvent(VER_TREE_CHANGED,func,applID);}

function   fireOnSmartFormChanged(applID){     fireEvent  (SMART_FORM_CHANGED,applID)};
function attachToSmartFormChanged(func,applID){_attachEvent(SMART_FORM_CHANGED,func,applID);}

function   fireFilterChange(applID){     fireEvent  (FILTER_CHANGE,applID)};
function attachToFilterChange(func,applID){_attachEvent(FILTER_CHANGE,func,applID);}

function fireOnUnload(applID){fireEvent("onUnload",applID)};
 //****** Attachements
//***********************
function _eventsObject(create){
	if( create && !_eventsObject() )
		_top().oEvents = {};
	try{return _top().oEvents;
	}catch(e){return top.oEvents;}
	//locals
	function _top(){
		try{
			for( var Parent=_opener(); Parent && _opener(Parent); Parent = _opener(Parent) ){}
			try{ if( Parent )return Parent.top;	}catch(e){}
			return top;
		}catch(e){
			status = "Events:"+e.description;
			return top;
		}
		function _opener(w){ w = w || top;	return (w.dialogArguments||{}).opener || w.top.opener;	}
	}
}
